module.exports = {
  pluginOptions: {
    electronBuilder: {
      nodeIntegration: false, // Set to false to enable contextIsolation
      contextIsolation: true, // Explicitly set for clarity
      preload: 'src/preload.js', // Explicitly define the preload script path
      externals: ['better-sqlite3'],
      builderOptions: {
        appId: 'CheckVibe',
        productName: 'CheckVibe',
        win: {
          icon: 'public/app-icon.ico', // 修改为你的自定义图标
          target: 'nsis'
        },
        mac: {
          icon: 'public/app-icon.ico' // 修改为你的自定义图标（Mac系统应使用.icns格式）
        },
        linux: {
          icon: 'public/app-icon.ico' // 修改为你的自定义图标（Linux系统可使用.png格式）
        },
        nsis: {
          oneClick: false,
          allowToChangeInstallationDirectory: true,
          deleteAppDataOnUninstall: false
        },
        files: [
          "**/*"
        ],
        extraResources: [
          {
            from: 'node_modules/better-sqlite3/build/Release',
            to: 'app.asar.unpacked/node_modules/better-sqlite3/build/Release',
            filter: ['**/*']
          }
        ],
        asar: {
          smartUnpack: true
        },
        afterPack: async (context) => {
          const fs = require('fs');
          const path = require('path');
          
          // 需要删除的许可证文件路径
          const licensePaths = [
            path.join(context.appOutDir, 'LICENSE.electron.txt'),
            path.join(context.appOutDir, 'LICENSES.chromium.html')
          ];
          
          // 删除许可证文件
          for (const licensePath of licensePaths) {
            if (fs.existsSync(licensePath)) {
              console.log(`正在删除: ${licensePath}`);
              fs.unlinkSync(licensePath);
            } else {
              console.log(`文件不存在: ${licensePath}`);
            }
          }
        }
      }
    }
  },
  configureWebpack: {
    externals: {
      'better-sqlite3': 'commonjs better-sqlite3'
    }
  },
  // chainWebpack: config => {
  //   config.module
  //     .rule('vue')
  //     .use('vue-loader')
  //     .tap(options => {
  //       options.compilerOptions = {
  //         ...options.compilerOptions,
  //         whitespace: 'preserve'
  //       };
  //       return options;
  //     });
  // },
  css: {
    loaderOptions: {
      scss: {
        // For sass-loader v8+ use additionalData
        // For sass-loader v7 or older use data
        additionalData: `@import "~@/assets/scss/_variables.scss";`
      }
    }
  }
};
